﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace InpatientManagementSystem
{
    public partial class Form6 : Form
    {
        MySqlConnection myConnection = new MySqlConnection("server=localhost;user=root;password=786452as;database=zhuyuan;port=3306;charset=utf8");
        public Form6()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            myConnection.Open();
            string query="update";
            MySqlCommand myCommand = new MySqlCommand(query, myConnection);
            int n = myCommand.ExecuteNonQuery();
            if (n > 0)
            {
                MessageBox.Show("该病人成功出院！");
            }
            else
            {
                MessageBox.Show("失败!请重新尝试");
            }
            myConnection.Close();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(System.Windows.Forms.Keys.Enter))
            {
                string query1 = "select";
                string query2 = "select sum";
                MySqlCommand myCommand = new MySqlCommand(query1, myConnection);
                MySqlDataReader myReader = myCommand.ExecuteReader();
                myCommand = new MySqlCommand(query2, myConnection);
                MySqlDataReader myReader2 = myCommand.ExecuteReader();
                try
                {
                    if (!myReader.Read())
                    {
                        MessageBox.Show("没有该病历号！");
                    }
                    else
                    {
                        while (myReader.Read())
                        {
                            ListViewItem lvi = new ListViewItem(myReader.GetString(0));
                            lvi.SubItems.Add(myReader.GetString(1));
                            lvi.SubItems.Add(myReader.GetString(2));
                            listView1.Items.Add(lvi);
                        }
                    }
                    if (myReader2.Read())
                    {
                        label2.Text += myReader2.GetString(0);
                    }
                }
                finally
                {
                    myReader.Close();
                    myReader2.Close();
                    myConnection.Close();
                }
            }
        }
    }
}
